Add more tests:
authorSondre Lefsaker <sondrele@stud.ntnu.no>
Sat, 2 May 2015 23:11:46 +0000 (01:11 +0200)
committerSondre Lefsaker <sondrele@stud.ntnu.no>
Sat, 2 May 2015 23:16:20 +0000 (01:16 +0200)
- `build_with_args_to_one_of_multiple_binaries`, verify that only one bin gets built
- `fails_with_args_to_all_binaries`
- `build_with_args_to_one_of_multiple_tests`, same behavious as for the binaries
- `build_foo_with_bar_dependency`, verify that bar dependency gets built and only foo gets compiled with args
- `build_only_bar_dependency`, build the bar package, that foo depends, on with the extra args

tests/test_cargo_rustc.rs

index 21cd75aa96f5e9bd2ac88ffede01c7fc9f3b4e99..3729558c9cf850c1d4a33d1c22c1ea5535cfc782 100644 (file)
@@ -120,3 +120,174 @@ test!(fails_when_trying_to_build_main_and_lib_with_args {
                 .with_status(101)
                 .with_stderr("extra arguments to `rustc` can only be invoked for one target"));
 });
+
+test!(build_with_args_to_one_of_multiple_binaries {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/bin/foo.rs", r#"
+            fn main() {}
+        "#)
+        .file("src/bin/bar.rs", r#"
+            fn main() {}
+        "#)
+        .file("src/bin/baz.rs", r#"
+            fn main() {}
+        "#)
+        .file("src/lib.rs", r#" "#);
+
+    assert_that(p.cargo_process("rustc").arg("-v").arg("--bin").arg("bar")
+                .arg("--").arg("-Z").arg("unstable-options"),
+                execs()
+                .with_status(0)
+                .with_stdout(format!("\
+{compiling} foo v0.0.1 ({url})
+{running} `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
+        --out-dir {dir}{sep}target{sep}debug [..]`
+{running} `rustc src{sep}bin{sep}bar.rs --crate-name bar --crate-type bin -g \
+        -Z unstable-options [..]`
+",
+                compiling = COMPILING, running = RUNNING, sep = SEP,
+                dir = p.root().display(), url = p.url())));
+});
+
+test!(fails_with_args_to_all_binaries {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/bin/foo.rs", r#"
+            fn main() {}
+        "#)
+        .file("src/bin/bar.rs", r#"
+            fn main() {}
+        "#)
+        .file("src/bin/baz.rs", r#"
+            fn main() {}
+        "#)
+        .file("src/lib.rs", r#" "#);
+
+    assert_that(p.cargo_process("rustc").arg("-v")
+                .arg("--").arg("-Z").arg("unstable-options"),
+                execs()
+                .with_status(101)
+                .with_stderr("extra arguments to `rustc` can only be invoked for one target"));
+});
+
+test!(build_with_args_to_one_of_multiple_tests {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("tests/foo.rs", r#" "#)
+        .file("tests/bar.rs", r#" "#)
+        .file("tests/baz.rs", r#" "#)
+        .file("src/lib.rs", r#" "#);
+
+    assert_that(p.cargo_process("rustc").arg("-v").arg("--test").arg("bar")
+                .arg("--").arg("-Z").arg("unstable-options"),
+                execs()
+                .with_status(0)
+                .with_stdout(format!("\
+{compiling} foo v0.0.1 ({url})
+{running} `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
+        --out-dir {dir}{sep}target{sep}debug [..]`
+{running} `rustc tests{sep}bar.rs --crate-name bar --crate-type bin -g \
+        -Z unstable-options [..]--test[..]`
+",
+                compiling = COMPILING, running = RUNNING, sep = SEP,
+                dir = p.root().display(), url = p.url())));
+});
+
+test!(build_foo_with_bar_dependency {
+    let foo = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies.bar]
+            path = "../bar"
+        "#)
+        .file("src/main.rs", r#"
+            extern crate bar;
+            fn main() {
+                bar::baz()
+            }
+        "#);
+    let bar = project("bar")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.1.0"
+            authors = []
+        "#)
+        .file("src/lib.rs", r#"
+            pub fn baz() {}
+        "#);
+    bar.build();
+
+    assert_that(foo.cargo_process("rustc").arg("-v").arg("--").arg("-Z").arg("unstable-options"),
+                execs()
+                .with_status(0)
+                .with_stdout(format!("\
+{compiling} bar v0.1.0 ({url})
+{running} `[..] -g -C [..]`
+{compiling} foo v0.0.1 ({url})
+{running} `[..] -g -Z unstable-options [..]`
+",
+                compiling = COMPILING, running = RUNNING,
+                url = foo.url())));
+});
+
+test!(build_only_bar_dependency {
+    let foo = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies.bar]
+            path = "../bar"
+        "#)
+        .file("src/main.rs", r#"
+            extern crate bar;
+            fn main() {
+                bar::baz()
+            }
+        "#);
+    let bar = project("bar")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.1.0"
+            authors = []
+        "#)
+        .file("src/lib.rs", r#"
+            pub fn baz() {}
+        "#);
+    bar.build();
+
+    assert_that(foo.cargo_process("rustc").arg("-v").arg("-p").arg("bar")
+                .arg("--").arg("-Z").arg("unstable-options"),
+                execs()
+                .with_status(0)
+                .with_stdout(format!("\
+{compiling} bar v0.1.0 ({url})
+{running} `[..]--crate-name bar --crate-type lib [..] -Z unstable-options [..]`
+",
+                compiling = COMPILING, running = RUNNING,
+                url = foo.url())));
+});